package com.glenet.salary.dao;

import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.RowBounds;
import org.apache.ibatis.session.SqlSession;

import com.glenet.salary.entities.HrSalary;
import com.glenet.salary.util.SessionFactoryUtil;

public class HrSalaryDao extends HrDaoSuport {

	public int batch(List<HrSalary> list) {
		int effect = 0;
		try {
			SqlSession session = SessionFactoryUtil.getSessionFactory().openSession(ExecutorType.BATCH);
			for (HrSalary in : list) {
				session.insert("HrSalary.insert", in);
			}
			session.commit();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return effect;
	}

	@SuppressWarnings("unchecked")
	public List<HrSalary> alpha(String name, String idcard, String time) {
		List<HrSalary> list = new ArrayList<HrSalary>();
		try {
			SqlSession session = SessionFactoryUtil.getSessionFactory().openSession(ExecutorType.BATCH);
			Map<String, String> map = new Hashtable<String, String>();
			map.put("name", name);
			map.put("idcard", idcard);
			map.put("time", time);
			list = session.selectList("HrSalary.alpha", map);
			session.commit();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return list;
	}

	@SuppressWarnings("unchecked")
	public List<HrSalary> list(int offset, int limit) {
		List<HrSalary> list = new ArrayList<HrSalary>();
		try {
			SqlSession session = SessionFactoryUtil.getSessionFactory().openSession();
			list = session.selectList("HrSalary.select", null, new RowBounds(offset, limit));
			session.commit();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return list;
	}
}
